
<?php
/**
 * DCRM Debian List
 *
 * This file is part of WEIPDCRM.
 * 
 * WEIPDCRM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WEIPDCRM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with WEIPDCRM.  If not, see <http://www.gnu.org/licenses/>.
 */

session_start();
define("DCRM",true);
$activeid = 'userid';

if (isset($_SESSION['connected']) && $_SESSION['connected'] === true) {
	require_once("header.php");
	class_loader('CorePage');

	if (!isset($_GET['action'])) {
		if (isset($_GET['search'])) {
?>
				<h2><?php _e('Manage Packages'); ?></h2>
				<br />
				<h3 class="navbar"><span><a href="center.php"><?php _e('All Packages'); ?></a></span>　<span><?php _e('Search Packages'); ?></span></h3>
					<br />
					<form class="form-horizontal" method="GET" action="center.php" >
					<div class="group-control">
						<label class="control-label"><?php _e('Search Content'); ?></label>
						<div class="controls">
							<input type="hidden" name="action" value="search" />
							<input class="input-xlarge" name="contents" required="required" />
						</div>
					</div>
					<br />
					<div class="group-control">
						<label class="control-label"><?php _e('Search Type'); ?></label>
						<div class="controls">
							<select name="type" >
							<option value="1" selected="selected"><?php _e('Identifier'); ?></option>
							<option value="2"><?php _e('Name'); ?></option>
							<option value="3"><?php _e('Author'); ?></option>
							<option value="4"><?php _e('Description'); ?></option>
							<option value="5"><?php _e('Maintainer'); ?></option>
							<option value="6"><?php _e('Sponsor'); ?></option>
							<option value="7"><?php _e('Section'); ?></option>
							<option value="8"><?php _e('Tag'); ?></option>
							</select>
						</div>
					</div>
					<br />
					<div class="form-actions">
						<div class="controls">
							<button type="submit" class="btn btn-success"><?php _e('Search'); ?></button>
						</div>
					</div>
					</form>
				<br />
<?php
		} else {
?>
				<h2><?php _e('用户管理'); ?></h2>
				<br />
				<h3 class="navbar"><span><?php _e('所有用户'); ?></span>　<!--span><a href="center.php?search=yes"><?php _e('搜索用户'); ?></a></span--></h3>
<?php
			if (isset($_GET['page'])) {
				$page = $_GET['page'];
			} elseif (isset($_SESSION['page'])) {
				$page = $_SESSION['page'];
			} else {
				$page = 1;
			}
			if ($page <= 0 OR $page >= 50) {
				$page = 1;
			}
			unset($_SESSION['contents']);
			unset($_SESSION['type']);
			$_SESSION['page'] = $page;
			$row_start = $page * 50 - 50;
			$lists = DB::fetch_all("SELECT `ID`, `User`,`Logo`,`Openid`,`Packages`,`Collection`,`TimeStamp` FROM `".DCRM_CON_PREFIX."User` ORDER BY `ID` DESC LIMIT " . (string)$row_start. ",50");
?>
								<table class="table"><thead><tr>
								  <th style="width:40px;"><ul class="ctl">ID</ul></th>
								  <th style="width:280px;"><ul class="ctl"><?php _e('用户名'); ?></ul></th>
                                  <th style="width:300px;"><ul class="ctl"><?php _e('OPENID'); ?></ul></th>
                                  <th style="width:200px;"><ul class="ctl"><?php _e('收藏数量'); ?></ul></th>
                                  <th style="width:200px;"><ul class="ctl"><?php _e('上传数量'); ?></ul></th>
                                  <th style="width:200px;"><ul class="ctl"><?php _e('上传权限'); ?></ul></th>
                                  <th style="width:200px;"><ul class="ctl"><?php _e('注册时间'); ?></ul></th>
								</tr></thead><tbody>
<?php
			foreach ($lists as $list) {
?>
                                 
								<tr>									
									<td height="20"><ul class="ctl"><?php echo($list['ID']); ?></ul></td>
								   <th><ul class="ctl"><img class="icon" src="<?php echo htmlspecialchars($list['Logo']); ?>" style="border-radius: 50%; width: 30px; height: 30px; box-shadow:0 0 1px #AAA;padding:1px;margin-right: 1px;"><?php echo htmlspecialchars($list['User']); ?></ul></th>
									<td><ul class="ctl"><?php echo(htmlspecialchars($list['Openid'])); ?></ul></td>
<?php
	$num = DB::result_first("SELECT count(*) FROM `".DCRM_CON_PREFIX."Collection` WHERE `UserOpenID`='".$list['Openid']."'");
?>                                    
                                  <td><ul class="ctl"><?php echo($num); ?></ul></td> 
                                   <td><ul class="ctl"><?php echo($list['Collection']); ?></ul></td>
                                    
                                  <td><a href="userid.php?Packages=1&id=<?php echo $list['ID']; ?>" class="close"><?php if($list['Packages']=='申请中'){echo '<span style="color: #EE0000;">申请中</span>';}if($list['Packages']==null){echo '未开通';}if($list['Packages']=='0'){ echo '未开通';}if($list['Packages']=='1'){echo '<span style="color: #ADFF2F;">已开通</span>';} ?></a></td>
								  <td><ul class="ctl"><?php echo($list['TimeStamp']); ?></ul></td>
                                  </tr>
                                  
<?php
			}
?>

                                  </tbody></table>
<?php
  
if(isset($_GET['Packages'])){
  $shzt_id = (int)$_GET['id'];
  $oid=$_GET['Packages'];
	if($row=DB::result_first("update `".DCRM_CON_PREFIX."User` set `Packages`='".$oid."' WHERE `ID`='".$shzt_id."'")){
      
   
} else {
 echo "<script>alert('开通成功');parent.location.href='/manage/userid.php';</script>";   
	}
}
?>
<?php
			$packages_count = DB::result_first("SELECT count(*) FROM `".DCRM_CON_PREFIX."User`");
			$params = array('total_rows' => (int)$packages_count, 'method' => 'html', 'parameter' => 'userid.php?page=%page', 'now_page'  => $page, 'list_rows' => 50);
			$page = new Core_Lib_Page($params);
			echo('<div class="page">' . $page->show(2) . '</div>');
		
?>
		
	<script type="text/javascript">
	function show(stat) {
		sli = document.getElementById('sli');
		
		if (stat == 1) {
			sli.innerHTML = '<a href="javascript:opt(4)"><?php _e('Hide Package'); ?></a>';
		} else {
			sli.innerHTML = '<a href="javascript:opt(5)"><?php _e('Display Package'); ?></a>';
		}
		document.getElementById('mbar').style.display = "";
	}
	</script>
</body>
</html>
<?php
      }
    }                
} else {
	$_SESSION['referer'] = $_SERVER['REQUEST_URI'];
	header("Location: login.php");
	exit();
}



?>